package problems.daily;

/**
 * 299. 猜数字游戏
 *
 * @author habitplus
 * @version: 1.0
 * @history: create by guan at 2024/3/10 17:58
 */
public class DT299 {
    public String getHint(String secret, String guess) {
        int[] cntMap = new int[10];
        int bull = 0;
        int total = 0;

        // 计算 bull，并且计数
        for (int i = 0; i < secret.length(); ++i) {
            if (secret.charAt(i) == guess.charAt(i)) {
                ++bull;
            }
            ++cntMap[secret.charAt(i) - '0'];
        }

        // 计算总数
        for (char c : guess.toCharArray()) {
            if (cntMap[c - '0'] > 0) {
                ++total;
                --cntMap[c - '0'];
            }
        }

        StringBuilder res = new StringBuilder();
        res.append(bull);
        res.append('A');
        res.append(total - bull);
        res.append('B');

        return res.toString();
    }
}
